<script type="text/javascript" src="message/angular/lib/avatarEditUpload/scripts/swfobject.js"></script>
<script type="text/javascript" src="message/angular/lib/avatarEditUpload/scripts/fullAvatarEditor.js"></script>

<div class="avatarEditer">
	<div id="swfContainer">
		本组件需要安装Flash Player后才可使用，请从
		<a href="http://www.adobe.com/go/getflashplayer">这里</a>下载安装。
	</div>
</div>

<script type="text/javascript">

	function getUploadUrl(){
		var url = YYIMChat.getServletPath().REST_RESOURCE_SERVLET + YYIMChat.getTenancy().ETP_KEY + '/' + YYIMChat.getTenancy().APP_KEY + '/upload?token=' + YYIMChat.getToken();
		var params = {
			mediaType: 1,
			creator: YYIMChat.getUserNode(),
			receiver: YYIMChat.getUserNode(),
			original: 1,
			size: 1024
		};
		url += '&' + jQuery.param(params);
		return url;
	}


	
	swfobject.addDomLoadEvent(function() {
		var swf = new fullAvatarEditor("message/angular/lib/avatarEditUpload/fullAvatarEditor.swf", "message/angular/lib/avatarEditUpload/expressInstall.swf", "swfContainer", {
			id: 'swf',
			upload_url: getUploadUrl(), //上传接口
			method: 'post', //传递到上传接口中的查询参数的提交方式。更改该值时，请注意更改上传接口中的查询参数的接收方式
			src_upload: 0, //是否上传原图片的选项，有以下值：0-不上传；1-上传；2-显示复选框由用户选择
			avatar_box_border_width: 0,
			avatar_sizes: '100*100',
			avatar_sizes_desc: '100*100像素'
		}, function(msg) {
			console.log('avatarEditer:', msg);
			switch (msg.code) {
				case 1:
					//                          alert("页面成功加载了组件！");
					break;
				case 2:
					//                          alert("已成功加载图片到编辑面板。");
					break;
				case 3:
					if (msg.type == 0) {
						alert("摄像头已准备就绪且用户已允许使用。");
					} else if (msg.type == 1) {
						alert("摄像头已准备就绪但用户未允许使用！");
					} else {
						alert("摄像头被占用！");
					}
					break;
				case 5:
					if (msg.type == 0) {
						if (msg.content.sourceUrl) {
							alert("原图已成功保存至服务器，url为：\n" + 　msg.content.sourceUrl + "\n\n" + "头像已成功保存至服务器，url为：\n" + msg.content.avatarUrls.join("\n\n") + "\n\n传递的userid=" + msg.content.userid + "&username=" + msg.content.username);
						} else {
							alert("头像已成功保存至服务器，url为：\n" + msg.content.avatarUrls.join("\n\n") + "\n\n传递的userid=" + msg.content.userid + "&username=" + msg.content.username);
						}
					}
					break;
			}
		});
	});
</script>